package edu.mse.camel.client.whiteboard.diagram.providers;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

import edu.mse.camel.client.whiteboard.WhiteboardPackage;
import edu.mse.camel.client.whiteboard.diagram.edit.parts.CylinderNameEditPart;
import edu.mse.camel.client.whiteboard.diagram.edit.parts.DiamondNameEditPart;
import edu.mse.camel.client.whiteboard.diagram.edit.parts.EllipseNameEditPart;
import edu.mse.camel.client.whiteboard.diagram.edit.parts.RectangleNameEditPart;
import edu.mse.camel.client.whiteboard.diagram.edit.parts.RoundedRectangleNameEditPart;
import edu.mse.camel.client.whiteboard.diagram.parsers.MessageFormatParser;
import edu.mse.camel.client.whiteboard.diagram.part.WhiteboardVisualIDRegistry;

/**
 * @generated
 */
public class WhiteboardParserProvider extends AbstractProvider implements
		IParserProvider {

	/**
	 * @generated
	 */
	private IParser cylinderName_4001Parser;

	/**
	 * @generated
	 */
	private IParser getCylinderName_4001Parser() {
		if (cylinderName_4001Parser == null) {
			cylinderName_4001Parser = createCylinderName_4001Parser();
		}
		return cylinderName_4001Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createCylinderName_4001Parser() {
		EAttribute[] features = new EAttribute[] { WhiteboardPackage.eINSTANCE
				.getShape_Name(), };
		MessageFormatParser parser = new MessageFormatParser(features);
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser ellipseName_4002Parser;

	/**
	 * @generated
	 */
	private IParser getEllipseName_4002Parser() {
		if (ellipseName_4002Parser == null) {
			ellipseName_4002Parser = createEllipseName_4002Parser();
		}
		return ellipseName_4002Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createEllipseName_4002Parser() {
		EAttribute[] features = new EAttribute[] { WhiteboardPackage.eINSTANCE
				.getShape_Name(), };
		MessageFormatParser parser = new MessageFormatParser(features);
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser rectangleName_4003Parser;

	/**
	 * @generated
	 */
	private IParser getRectangleName_4003Parser() {
		if (rectangleName_4003Parser == null) {
			rectangleName_4003Parser = createRectangleName_4003Parser();
		}
		return rectangleName_4003Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createRectangleName_4003Parser() {
		EAttribute[] features = new EAttribute[] { WhiteboardPackage.eINSTANCE
				.getShape_Name(), };
		MessageFormatParser parser = new MessageFormatParser(features);
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser diamondName_4004Parser;

	/**
	 * @generated
	 */
	private IParser getDiamondName_4004Parser() {
		if (diamondName_4004Parser == null) {
			diamondName_4004Parser = createDiamondName_4004Parser();
		}
		return diamondName_4004Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createDiamondName_4004Parser() {
		EAttribute[] features = new EAttribute[] { WhiteboardPackage.eINSTANCE
				.getShape_Name(), };
		MessageFormatParser parser = new MessageFormatParser(features);
		return parser;
	}

	/**
	 * @generated
	 */
	private IParser roundedRectangleName_4005Parser;

	/**
	 * @generated
	 */
	private IParser getRoundedRectangleName_4005Parser() {
		if (roundedRectangleName_4005Parser == null) {
			roundedRectangleName_4005Parser = createRoundedRectangleName_4005Parser();
		}
		return roundedRectangleName_4005Parser;
	}

	/**
	 * @generated
	 */
	protected IParser createRoundedRectangleName_4005Parser() {
		EAttribute[] features = new EAttribute[] { WhiteboardPackage.eINSTANCE
				.getShape_Name(), };
		MessageFormatParser parser = new MessageFormatParser(features);
		return parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case CylinderNameEditPart.VISUAL_ID:
			return getCylinderName_4001Parser();
		case EllipseNameEditPart.VISUAL_ID:
			return getEllipseName_4002Parser();
		case RectangleNameEditPart.VISUAL_ID:
			return getRectangleName_4003Parser();
		case DiamondNameEditPart.VISUAL_ID:
			return getDiamondName_4004Parser();
		case RoundedRectangleNameEditPart.VISUAL_ID:
			return getRoundedRectangleName_4005Parser();
		}
		return null;
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(WhiteboardVisualIDRegistry.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(WhiteboardVisualIDRegistry.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (WhiteboardElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
